package com.ar4j.type;

/**
 * Defines the functionality required of all type converters
 */
public interface ITypeConverter<O, S> {

  /**
   * Convert the value of an object to its storage representation
   * 
   * @param value value to convert
   * @return the value to store
   */
  S convertToStorage(O value);
  
  /**
   * Convert the value retrieved from storage into its object representation
   * 
   * @param storageValue value to convert
   * @return the converted value
   */
  O convertFromStorage(S storageValue);
  
  /**
   * @return the SQL type to be used to store the storage value
   */
  int getSqlType();
  
  /**
   * @return the type of the object representation
   */
  Class<O> getObjectType();
  
  /**
   * @return the type of the storage representation
   */
  Class<S> getStorageType();
  
  /**
   * An optional mechanism to notify the converter of object and storage types.
   * The implementing class should take care not to allow this method to be executed 
   * multiple types.
   */
  void setTypes(Class<O> objectType, Class<S> storageType);
  
}
